package log

import (
	"io"
)

var (
	_logger Logger = NewLogger()
)

// 日志接口定义
type Logger interface {
	//标准接口
	Log(lv Level, args ...any) error
	Logf(lv Level, format string, args ...any) error
	Logr(lv Level, r io.Reader) error //写大块日志
	//自定义calldepth，与log库一样
	LogDepth(calldepth int, lv Level, args ...any) error
	LogDepthf(calldepth int, lv Level, format string, args ...any) error
	LogDepthr(calldepth int, lv Level, r io.Reader) error //写大块日志
	//关闭日志
	io.Closer
}

func GetLogger() Logger {
	return _logger
}

// 设置标准日志接口
func SetLogger(logger Logger) {
	_logger = logger
}

// 日志输出全局接口
func Log(lv Level, args ...any) error {
	return _logger.LogDepth(2, lv, args...)
}

func Logf(lv Level, format string, args ...any) error {
	return _logger.LogDepthf(2, lv, format, args...)
}

func Logr(lv Level, r io.Reader) error {
	return _logger.LogDepthr(2, lv, r)
}

// calldepth从0开始计算
func LogDepth(calldepth int, lv Level, args ...any) error {
	return _logger.LogDepth(calldepth+1, lv, args...)
}

func LogDepthf(calldepth int, lv Level, format string, args ...any) error {
	return _logger.LogDepthf(calldepth+1, lv, format, args...)
}

func LogDepthr(calldepth int, lv Level, r io.Reader) error {
	return _logger.LogDepthr(calldepth+1, lv, r)
}

func Debug(args ...any) error {
	return _logger.LogDepth(2, DEBUG, args...)
}

func Debugf(format string, args ...any) error {
	return _logger.LogDepthf(2, DEBUG, format, args...)
}

func Info(args ...any) error {
	return _logger.LogDepth(2, INFO, args...)
}

func Infof(format string, args ...any) error {
	return _logger.LogDepthf(2, INFO, format, args...)
}

func Warn(args ...any) error {
	return _logger.LogDepth(2, WARN, args...)
}

func Warnf(format string, args ...any) error {
	return _logger.LogDepthf(2, WARN, format, args...)
}

func Error(args ...any) error {
	return _logger.LogDepth(2, ERROR, args...)
}

func Errorf(format string, args ...any) error {
	return _logger.LogDepthf(2, ERROR, format, args...)
}

func Fatal(args ...any) error {
	return _logger.LogDepth(2, FATAL, args...)
}

func Fatalf(format string, args ...any) error {
	return _logger.LogDepthf(2, FATAL, format, args...)
}
